
#include "Twi_Quene.h" 
#include <stdio.h>
#include <string.h>

#define MAX 40

typedef struct Queues
{
    Twi_Data date[MAX];
    uint8 front;
    uint8 rear;
}Queue;

static Queue queue;

/**
  * @brief  initnal twi queue
  * @param  void
  * @retval void
  */
void Twi_QueueInit(void)
{
    queue.front = queue.rear = 0;
}

/**
  * @brief  queue push
  * @param  value: element
  * @retval 0 succes else failed
  */
uint8 Twi_PushQueue(Twi_Data value)
{
    if ((queue.rear + 1) % MAX != queue.front)
    {
        queue.date[queue.rear] = value;
        queue.rear = (queue.rear+1)%MAX;
        return 0;
    }
    else
    {
        return 1;
    }
}

/**
  * @brief  queue push
  * @param  data: Pointer Twi_Data
  * @retval 0 succes else failed
  */
uint8 Twi_PopQueue(Twi_Data* data)
{
    if (queue.front != queue.rear)
    {
        *data = queue.date[queue.front];
        queue.front = (queue.front+1)%MAX;
        return 0;
    }
    return 1;
}

